package cn.cdcoder.solr.insert;

import cn.cdcoder.solr.BaseSort;

/**
 * 希尔排序
 * @author xusirun
 * @Date 2017/3/21 10:43
 **/
public class ShellSort extends BaseSort {
    public static void main(String[] args)
    {
        int[] a = getData(20);

        System.out.println();
        System.out.println("排序之后：");
        for (int i = 0; i < a.length; i++)
        {
            System.out.print(a[i] + " ");
        }

    }

    // 希尔排序
    private static  int[] sort(int[] array){
        int d = array.length;
        while (true)
        {
            d = d / 2;
            for (int x = 0; x < d; x++)
            {
                for (int i = x + d; i < array.length; i = i + d)
                {
                    int temp = array[i];
                    int j;
                    for (j = i - d; j >= 0 && array[j] > temp; j = j - d)
                    {
                        array[j + d] = array[j];
                    }
                    array[j + d] = temp;
                }
            }
            if (d == 1)
            {
                break;
            }
        }
        return array;
    }
}
